package com.xlabs.client.DTO;

import com.google.gwt.user.client.rpc.IsSerializable;

import java.util.Date;
import java.io.Serializable;

/**
 * Question data transfer object.
 */
public class QuestionDTO implements Serializable, IsSerializable, EntityDTO
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1942693158061460996L;

	/**
	 * The text comment.
	 */
	private String questionText;

	/**
	 * The start time of video in seconds to which this question relates.
	 */
	private Integer startTime;

	/**
	 * The end time of video in seconds to which this question relates.
	 */
	private Integer endTime;

	/**
	 * When created.
	 */
	private Date createdOn;

	/**
	 * Created by user.
	 */
	private String createdBy;

	/**
	 * Encoded key of the corresponding data object.
	 */
	private String encodedKey;

	/**
	 * Start time index.
	 */
	private String startTimeIndex;
	
	/**
	 * whether this question has been answered or not. 
	 */
	private Boolean isAnswered;
	
	/**
	 * The answer reply is available. It's only used in the client side.
	 */
	private ReplyDTO answer;

	/**
	 * Initializes an instance of TimedComment.
	 * 
	 * @param questionText
	 *            The comment.
	 * @param startTime
	 *            the start of corresponding video interval.
	 * @param endTime
	 *            the end of corresponding video interval.
	 * @param startTimeIndex
	 *            start time index.
	 */
	public QuestionDTO(String questionText, int startTime, int endTime,
			Date createdOn, String startTimeIndex, boolean isAnswered)
	{
		if (endTime < startTime)
		{
			throw new IllegalArgumentException(
					"startTime should be less than or equal to endTime");
		}

		this.questionText = questionText;
		this.startTime = startTime;
		this.endTime = endTime;
		this.createdOn = createdOn;
		this.startTimeIndex = startTimeIndex;
		this.isAnswered = isAnswered;
		this.answer = null;
	}

	/**
	 * Public no-arg contructor.
	 */
	public QuestionDTO()
	{
	}

	/**
	 * Gets question text.
	 * 
	 * @return question text.
	 */
	public String getQuestionText()
	{
		return this.questionText;
	}

	/**
	 * Sets question text.
	 * 
	 * @param questionText
	 *            The text comment.
	 */
	public void setQuestionText(String questionText)
	{
		this.questionText = questionText;
	}

	/**
	 * Gets createdOn.
	 * 
	 * @return time of creation.
	 */
	public Date getCreatedOn()
	{
		return createdOn;
	}

	/**
	 * Sets time of creation.
	 * 
	 * @param createdOn
	 *            time of creation.
	 */
	public void setCreatedOn(Date createdOn)
	{
		this.createdOn = createdOn;
	}

	/**
	 * Gets createdBy.
	 * 
	 * @return creator.
	 */
	public String getCreatedBy()
	{
		return createdBy;
	}

	/**
	 * Sets createdBy.
	 * 
	 * @param createdBy
	 *            creator.
	 */
	public void setCreatedBy(String createdBy)
	{
		this.createdBy = createdBy;
	}

	/**
	 * Gets {@link #startTime}
	 * 
	 * @return {@link #startTime}
	 */
	public Integer getStartTime()
	{
		return startTime;
	}

	/**
	 * Sets {@link #startTime}
	 * 
	 * @param startTime
	 *            {@link #startTime}
	 */
	public void setStartTime(Integer startTime)
	{
		this.startTime = startTime;
	}

	/**
	 * Gets {@link #endTime}
	 * 
	 * @return {@link #endTime}
	 */
	public Integer getEndTime()
	{
		return endTime;
	}

	/**
	 * Sets {@link #endTime}
	 * 
	 * @param endTime
	 *            {@link #endTime}
	 */
	public void setEndTime(Integer endTime)
	{
		this.endTime = endTime;
	}

	/**
	 * Gets {@link #encodedKey}
	 * 
	 * @return {@link #encodedKey}
	 */
	public String getEncodedKey()
	{
		return encodedKey;
	}

	/**
	 * Sets {@link #encodedKey}
	 * 
	 * @param encodedKey
	 *            {@link #encodedKey}
	 */
	public void setEncodedKey(String encodedKey)
	{
		this.encodedKey = encodedKey;
	}

	/**
	 * @param startTimeIndex
	 *            the startTimeIndex to set
	 */
	public void setStartTimeIndex(String startTimeIndex)
	{
		this.startTimeIndex = startTimeIndex;
	}

	/**
	 * @return the startTimeIndex
	 */
	public String getStartTimeIndex()
	{
		return startTimeIndex;
	}
	
	public String toString()
	{
		return startTime + " : " + questionText + " - " + createdBy;
	}

	/**
	 * Setter for {@link #isAnswered()}
	 * @param isAnswered the isAnswered to set
	 */
	public void setAnswered(Boolean isAnswered)
	{
		this.isAnswered = isAnswered;
	}

	/**
	 * Getter for {@link #isAnswered()}
	 * @return the isAnswered
	 */
	public Boolean isAnswered()
	{
		return isAnswered;
	}

	/**
	 * Sets the answer reply.
	 * @param answer the answer to set
	 */
	public void setAnswer(ReplyDTO answer)
	{
		this.answer = answer;
	}

	/**
	 * @return the answer reply.
	 */
	public ReplyDTO getAnswer()
	{
		return answer;
	}
}
